<?php

/**
 * @name SoftRank Plugin Center for Discuz! 7.2.0 GBK
 * @copyright 2008-2009 SoftRank Research Center
 * @author http://www.softrank.net
 * @version 1.0.0.0
 */

class User
{
	var $uid;
	var $username;
	var $d_ext;
	var $p_ext;
	var $exp;
	var $rate;
	var $regtime;
	var $activated;

	function User(&$db, $ptablepre)
	{
		$this->Refresh($db, $ptablepre);
	}
	
	function Refresh(&$db, $ptablepre)
	{
		global $discuz_uid;
		if ($discuz_uid)
        {
        	$this->uid = $discuz_uid;
			$query = $db->query("SELECT * FROM `{$ptablepre}user` WHERE `uid`='{$discuz_uid}'");
			$tempUserInfo = $db->fetch_array($query);
			for ($i = 1; $i <= 4; $i++)
			{
				$this->p_ext[$i] = $tempUserInfo["ext{$i}"];
			}
			$this->rate = $tempUserInfo['activerate'];
			$this->exp = $tempUserInfo['exp'];
			$this->regtime = $tempUserInfo['regtime'];
			$this->activated = $tempUserInfo['activated'];
			
			global $tablepre;
			$query = $db->query("SELECT * FROM `{$tablepre}members` WHERE `uid`='{$discuz_uid}'");
			$tempUserInfo = $db->fetch_array($query);
			for ($i = 1; $i <= 8; $i++)
			{
				$this->d_ext[$i] = $tempUserInfo["extcredits{$i}"];
			}
			global $discuz_user;
			$this->username = $discuz_user;
		}
		else
		{
			$this->uid = 0;
			for ($i = 1; $i <= 4; $i++)
			{
				$this->p_ext[$i] = 0;
			}
			$this->rate = 0;
			$this->exp = 0;
			$this->regtime = 0;
			$this->activated = '0';
			for ($i = 1; $i <= 8; $i++)
			{
				$this->d_ext[$i] = $tempUserInfo["extcredits{$i}"];
			}
			global $lang;
			$this->username = $lang['string_guest'];
		}
	}
	
	function ToArray()
	{
		$user = array
		(
			'uid' => $this->uid,
			'username' => $this->username,
			'd_ext' => $this->d_ext,
			'p_ext' => $this->p_ext,
			'exp' => $this->exp,
			'rate' => $this->rate,
			'regtime' => $this->regtime,
			'activated' => $this->activated,
		);
		return $user;
	}
}

?>